/*
 * pH DataTable Javascript
 */

/*
 * Constructor
 *
 * Configuration Options:
 *
 * data                pH.Data Object.
 * container           Where to place the Table
 *
 */
 
pH.DataTable = function(config)
{
	this.data = config.data;

	// Create DataSource
	this.datasource = new YAHOO.util.DataSource(config.data.url);
	this.datasource.responseType = YAHOO.util.DataSource.TYPE_JSON;
	this.datasource.responseSchema =
	{
		resultsList: "result",
		fields: this.data.getFieldNames(),
		metaFields: {
			totalRecords: "total",
			foundRecords: "found"
		}
	};

	this.getColumns = function()
	{
		var columns = [];
		var datainfo = this.data.getFields();

		for (var i in datainfo)
		{
			columns.push({key: datainfo[i].name, label: datainfo[i].caption, sortable: true});
		}

		return columns;
	}

	// Create Table
	this.table = new YAHOO.widget.DataTable(config.container, this.getColumns(), this.datasource);

}

pH.require(['jqgrid/js/grid.locale-en.js', 'jqgrid/js/grid.base.js', 'jqgrid/js/grid.common.js']);
pH.info('pH+ DataTable module successfully enabled.');

